<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function fun(){
				console.log(`你输入的是${event.key},它的键值是${event.keyCode}`);
				if(event.keyCode<48||event.keyCode>57){
					console.error("输入的不是数字");
					event.preventDefault()
				}
			}
		</script>
	</head>
	<body>
		输入数字：<input type="text" onkeypress="fun()"/>
	</body>
</html>
